package yz;

import java.util.ArrayList;
import java.util.List;

/**
 * [234. 回文链表](https://leetcode-cn.com/problems/palindrome-linked-list/)
 *
 * @Author yangz
 * @Date 2022/10/11 21:38
 */
public class LeetCode234_PalindromeLinkedList {
    public boolean isPalindrome(ListNode head) {
        List<Integer> vals = new ArrayList<Integer>();

        ListNode cur = head;
        while (cur != null) {
            vals.add(cur.val);
            cur = cur.next;
        }

        int front = 0;
        int r = vals.size() - 1;
        while (front < r) {
            if (!vals.get(front).equals(vals.get(r))) {
                return false;
            }
            front++;
            r--;
        }

        return true;
    }

    static class ListNode {
        int val;
        ListNode next;

        public ListNode() {
        }

        public ListNode(int val) {
            this.val = val;
        }

        public ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }
}
